<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home-page></home-page>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp();
    const CommonTitle = {
      template: `
        <div>
          <h2>子组件</h2>  
          <button @click="emit">向父组件通信</button>
        </div>
      `,
      data() {
        return {
          msg: '子组件数据'
        }
      },
    methods: {
      emit() {
        // 触发子组件自定义事件
        this.$emit('biubiu', this.msg)
      }
    },
    }
    const HomePage = {
      template: `
        <div>
          <h1>首页</h1>  
          <common-title @biubiu="fn"></common-title>
          {{ msg }}
        </div>
      `,
      data() {
        return {
          msg: ''
        }
      },
      methods: {
        fn(msg) {
          this.msg = msg;
        }
      },
      components: {
        CommonTitle
      }
    }

    app.component('HomePage', HomePage)
    app.mount('#app')
  </script>
</body>
</html>